var jwt = require('jsonwebtoken');
module.exports = options => {
  return async function auth(ctx, next) {

    await next();
    if (ctx.path == '/login' || ctx.path == '/v1/register' || ctx.path =='/redirect'){
        return;
    }

    try {
      const token = ctx.cookies.get('token',{
        signed: false,
        encrypt: true
      });
      var decoded = jwt.verify(token, 'aaa');
    } catch(err) {
      ctx.body = {
        retcode: -90001,
        msg: '未登录'
      };
    }
    // if (!ctx.session || !ctx.session.userId){
    //   // ctx.redirect('/login');
    //
    // }
  };
};
